package com.lib.framework.widget.dialog

import android.content.Context
import androidx.databinding.DataBindingUtil
import com.lib.framework.R
import com.lib.framework.databinding.WidgetPromptDialogBinding

/**
 * 提示 对话框
 *
 * @author keanbin
 */
class PromptDialog(context: Context) : BaseDialog(context, R.style.defaultDialogTheme02) {

    companion object {

        /**
         *  样式
         */
        const val STYLE_OK = 1 // 成功 样式
        const val STYLE_ERROR = 2 // 失败 样式
    }

    private var mDataBinding: WidgetPromptDialogBinding? = null

    /**
     * 样式
     */
    private var mStyle = STYLE_OK

    init {
        initView()

        setCanceledOnTouchOutside(false)
        setCancelable(false)
    }

    private fun initView() {
        mDataBinding = DataBindingUtil.inflate(layoutInflater, R.layout.widget_prompt_dialog, null, false)
        mDataBinding?.let { dataBinding ->
            setContentView(dataBinding.root)
        }
    }

    /**
     * 设置样式：STYLE_OK、STYLE_ERROR
     */
    fun setStyle(style: Int): PromptDialog {
        when (style) {
            STYLE_OK -> {
                mStyle = style
                setIcon(R.mipmap.ic_ok)
            }

            STYLE_ERROR -> {
                mStyle = style
                setIcon(R.mipmap.ic_error)
            }
        }

        return this
    }

    /**
     * 设置 图标
     */
    fun setIcon(resId: Int): PromptDialog {
        mDataBinding?.ivIcon?.setImageResource(resId)
        return this
    }

    /**
     * 设置文本
     */
    fun setText(text: String): PromptDialog {
        mDataBinding?.tvText?.text = text
        return this
    }
}